﻿using System.IO;
using System.Text;
using System.Web.Mvc;
using System.Web.UI;
using Complaint.Models.Dtos;

namespace Complaint.Helpers
{
    public static class CommentGridHelper
    {
        public static string RenderPartialToString(this HtmlHelper htmlHelper, string controlName, object viewData)
        {
            var vd = new ViewDataDictionary(viewData);
            var urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);
            var vp = new ViewPage { ViewData = vd, ViewContext = htmlHelper.ViewContext, Url = urlHelper};
            var control = vp.LoadControl(controlName);

            vp.Controls.Add(control);

            var sb = new StringBuilder();
            using (var sw = new StringWriter(sb))
            {
                using (var tw = new HtmlTextWriter(sw))
                {
                    vp.RenderControl(tw);
                }
            }

            return sb.ToString();
        }

        public static string RenderComment(Comment comment)
        {
            var sb = new StringBuilder();

            sb.Append("<div>");
            sb.AppendFormat("<p>");

            return sb.ToString();
        }
    }
}
